package com.wyw.function.learning.common;

/**
 * @Title   折扣
 * @Description
 * @Author Mr Wu yewen.wu.china@gmail.com
 * Update History:
 * Author        Time            Content
 */
public class Discount {

    public enum CODE {
        NONE(0),
        SILVER(5),
        GOLD(10),
        PLATINUM(15),
        DIAMOND(20),
        ;


        private final int percentage;

        CODE(int percentage) {
            this.percentage = percentage;
        }
    }

    public static String applyDiscount(Quote quote) {
        return quote.getShopName() + " price is " + Discount.apply(quote.getPrice(), quote.getCode());
    }

    public static double apply(double price, CODE code) {
        delay();
        return price * (100 - code.percentage) / 100;
    }

    // 延迟方法
    private static void delay() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}